package com.gao.autowired;

import com.gao.autowired.constructor.ConstructorTest1;
import com.gao.autowired.constructor.ConstructorTest2;
import com.gao.autowired.known.TestKnownDemo;
import com.gao.autowired.nullwire.*;
import com.gao.autowired.setter.SetterTest1;
import com.gao.autowired.sort.WantSortBean;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @author GaoXi
 * @date 2022/2/24 19:33
 */
public class Starter {
    public static void main(String[] args) {
        ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("spring.xml");
        //5.1后构造方法直接不用autowire
        ConstructorTest1 bean = applicationContext.getBean(ConstructorTest1.class);
        System.out.println(bean);
        //多个构造函数
        ConstructorTest2 bean2 = applicationContext.getBean(ConstructorTest2.class);
        System.out.println(bean2);

        //setter方法必须有@Autowired
        SetterTest1 bean1 = applicationContext.getBean(SetterTest1.class);
        System.out.println(bean1);

        //集合注入顺序
        WantSortBean bean3 = applicationContext.getBean(WantSortBean.class);
        System.out.println(bean3);

        //@Nullable测试
        NullableAnnoDemo bean4 = applicationContext.getBean(NullableAnnoDemo.class);
        System.out.println(bean4);

        //Optional测试
        OptionalDemo bean5 = applicationContext.getBean(OptionalDemo.class);
        System.out.println(bean5);

        //@Autowire的require=false
        RequireFalseDemo bean6 = applicationContext.getBean(RequireFalseDemo.class);
        System.out.println(bean6);

        //知名Bean注入
        TestKnownDemo bean7 = applicationContext.getBean(TestKnownDemo.class);
        System.out.println(bean7);
    }

}
